package com.doeis.uwork.module;

import com.doeis.minaserver.NettyServer;
import com.doeis.minaserver.container.BasicModule;
import com.doeis.minaserver.session.ClientConnection;
import com.doeis.uwork.packet.MessagePacket;
import com.doeis.uwork.servce.MessageService;


public class MessagePacketRouter extends BasicModule {

	private MessageService messageService;
	
	public MessagePacketRouter() {
		super("Message Packet Router");
	}
	
	public MessagePacketRouter(String moduleName) {
		super(moduleName);
	}
	@Override
	public void start() {
		messageService = server.getT(MessageService.class);
	}

	@Override
	public void initialize(NettyServer server) {
		this.server = server;		
	}

	public void route(ClientConnection fromConn, MessagePacket packet) {
		switch ( packet.getCmd() ) {
		
		case MessagePacket.CMD_MSG_ADD:
			messageService.addMsg(fromConn, packet);
			break;
			
		case MessagePacket.CMD_MSG_LIST:
			messageService.listMsg(fromConn, packet);
			break;
			
		case MessagePacket.CMD_MSG_REPLY:
			messageService.replyMsg(fromConn, packet);
			break;
		
		default:
			break;
		}		
	}

}
